package com.leyou.auth.interceptors;

import com.leyou.auth.config.JwtProperties;
import com.leyou.auth.task.PrivilegeTokenHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

@Component //feign的拦截器
@EnableConfigurationProperties(JwtProperties.class)
public class AppTokenInterceptor implements RequestInterceptor {

    @Autowired
    private JwtProperties props;
    @Autowired
    private PrivilegeTokenHolder tokenHolder;

    @Override
    public void apply(RequestTemplate template) {
        //给所有的feign的请求，在feign的请求头中添加token
        template.header(props.getApp().getHeaderName(),tokenHolder.getToken());
    }
}
